#include <STC89C5xRC.H>
#include "delay.h"
#include "LCD1602.h"
#include "matrixkey.h"

unsigned char keynum;
unsigned int password,count;
void main()
{
	LCD_Init();
	LCD_ShowString(1,1,"PASSWORD:");
	//keynum = matrixkey();
	LCD_ShowNum(2,1,0,4);

	while(1)
	{
		keynum = matrixkey();
		if(keynum)
		{
			if(keynum<=10)
			{
				if(count<4)
				{
					password *=10;
					password += keynum%10;
				}
				count++;
				LCD_ShowNum(2,1,password,4);
			}
			if(keynum ==11)
			{
				if(password == 613)
				{
					LCD_ShowString(1,14,"OK ");
					password = 0;
					count = 0;
					LCD_ShowNum(2,1,0,4);
				}
				else
				{
					LCD_ShowString(1,14,"ERR");
					password = 0;
					count = 0;
					LCD_ShowNum(2,1,0,4);
				}
			}
			if(keynum == 12)
			{
				password = 0;
				count = 0;
				LCD_ShowNum(2,1,0,4);
			}

		}
	}
	
}
